<template>
  <div class="section-wrap hiddenlc" style="height:100%;margin-top: 40px;">
      <!-- 头部 -->
      <div class="headerBox">
        <div class="header">
          <x-icon type="ios-arrow-left" size="" class="icon-white" @click="goBack"></x-icon>
          安全检查台账
        </div>
      </div>
      <vue-better-scroll
      class="wrapper"
      ref="scrollqq"
      :scrollbar="scrollbarObj"
      :pullDownRefresh="pullDownRefreshObj"
      :pullUpLoad="pullUpLoadObj"
      :startY='parseInt(startY)'
      @pullingUp="onPullingUp"
    >
      <div class="form-section" style="margin-top: 40px;">
        <div class="form-item form-item-style1">
          <div class="label-title">
            <label>检查单位</label>
          </div>
          <div class="input_div" @click="getCompany(0)">
            <input type="text"
                   v-model="params.beDepartName"
                   :disabled="isDisabled"/>
            <x-icon type="ios-arrow-right" size="22" class="icon-right"></x-icon>
          </div>
        </div>
        <div class="form-item form-item-style1">
          <div class="label-title">
            <label>被检查单位</label>
          </div>
          <div class="input_div" @click="getCompany(1)">
            <input type="text"
                   v-model="params.projectName"
                   :disabled="isDisabled">
            <x-icon type="ios-arrow-right" size="22" class="icon-right"></x-icon>
          </div>
        </div>
         <div class="form-item form-item-style1">
          <div class="label-title">
            <label>检查类型</label>
          </div>
           <group>
             <popup-picker :data="checkTypeList"
                           v-model="checkType"
                           placeholder='请选择'></popup-picker>
           </group>
          <!--<div class="input_div">
            <input type="text"
                   v-model="params.checkDepartName"
                   :disabled="isDisabled"/>
            <input type="hidden" v-model="params.CheckDepartId"/>
            <x-icon type="ios-arrow-right" size="22" class="icon-right"></x-icon>
          </div>-->
        </div>
        <div class="form-item form-item-style1">
          <div class="label-title">
            <label>查询开始时间</label>
          </div>
          <group>
            <datetime v-model="startDate" format="YYYY-MM-DD" clear-text="清除" @on-clear="clearStartDate"></datetime>
          </group>
        </div>
        <div class="form-item form-item-style1">
          <div class="label-title">
            <label>查询结束时间</label>
          </div>
          <group>
            <datetime v-model="endDate" clear-text="清除" @on-clear="clearEndDate"></datetime>
          </group>
        </div>
         <p class="search-btn" @click="search">查询</p>
        <div class="info_div2">
          <div class="form-item">
            <div><span>安全检查次数：{{totalCount}}次</span></div>
          </div>
        </div>
        <div class="project_div">
          <ul class="project_list">
            <li v-for='(item,index) in accpentlist' :key="index" @click="$router.push({path:'./safeDetails',query:{planId:item.id}})">

              <h4 style="padding-top:3px;">
                {{item.projectName}}
              </h4>
              <p style="overflow:hidden;padding-right:30px;">
                <span>{{item.checkType}}</span><span style="float:right;">{{item.checkDate.substring(0,10)}}</span>
              </p>

              <x-icon type="ios-arrow-right" size="22" class="icon-right"></x-icon>
            </li>

          </ul>
        </div>
      </div>
    </vue-better-scroll>
    <div v-transfer-dom>
      <popup v-model="classValue" width="100%">
        <ztree
          :data="data"
          @nodeClick="nodeClick"
          :name="'departName'"
        ></ztree>
      </popup>
    </div>
  </div>

</template>
<script>
  import ztree from "@commonComponents/tree";
  import formatDate from "../../utils/formatDate";
  import VueBetterScroll from "vue2-better-scroll"
  import {
    XHeader,
    Tabbar,
    TabbarItem,
    Group,
    Cell,
    TransferDom,
    Popup
  } from "vux";

  export default {
    directives: {
      TransferDom
    },
    data() {
      return {
        num:0,
        classValue:false,
        checkTypeList:[],
        checkType:[],
        /*下拉刷新*/
        resultlist: [],
        scrollbarObj: {fade: true},
        pullDownRefreshObj: false,
        pullUpLoadObj: {
          threshold: 0,
          txt: {
            more: "加载更多",
            noMore: "没有更多数据了"
          }
        },
        startY: 0,
        scrollToX: 0,
        scrollToY: 0,
        scrollToTime: 700,
        isDisabled: true, // 是否禁止输入
        totalCount: 0, //量化考试
        accpentlist: [
        ],
        classValue: false,
        data: [],
        params: {
          startDate: "",
          endDate: "",
          checkDepartId: "",
          projectId:"",
          skipCount: 0,
          maxResultCount: 10
        },
        startDate: '',
        endDate: '',
        selectDepartType: 0
      };
    },
    components: {
      ztree,
      Popup,
      VueBetterScroll
    },
    created() {
     // this.search();
      // this.startDate = formatDate()
      this.params.projectName = 
      this.getData();
      this.getCheckTypeList()
    },
    mounted(){
        let that = this;
        this.$bridge.registerHandler("setToken", function(data) {
                         that.$store.state.Authorization =
          "Bearer " + data;
            //这里data ioS返回的是token值(字符串)
          //  that.search();
            that.getData();
            that.getCheckTypeList()
        });

        this.connectWebViewJavascriptBridge(function(bridge) {
            bridge.init(function(message, responseCallback) {});

            bridge.registerHandler("setToken", function(data) {
                             that.$store.state.Authorization =
          "Bearer " + data;
          //  that.search();
            that.getData();
            that.getCheckTypeList()
                  //这里data android返回的是token值(字符串)

            });
        });
        this.params.projectName = this.$store.state.departNanme
    },
    methods: {
      connectWebViewJavascriptBridge(callback) {
            if (window.WebViewJavascriptBridge) {
                callback(WebViewJavascriptBridge);
            } else {
                document.addEventListener(
                "WebViewJavascriptBridgeReady",
                function() {
                    callback(WebViewJavascriptBridge);
                },
                false
                );
            }
        },
      search() {
       /* if (this.startDate) {
          this.params.startDate = this.startDate + " 00:00:00";
        }
        if (this.endDate) {
          this.params.endDate = this.endDate + " 00:00:00";
        }
        if(this.checkType!=null&&this.checkType.length>0){
          this.params.checkType=this.checkType[0]
        }
       // this.params.skipCount = 0;
        this.$axiosAjax.getCheckList(this.params).then(res => {
          this.totalCount = res.data.result.totalCount;
          this.accpentlist = res.data.result.items;
        });*/
        if (new Date(this.startDate).getTime() > new Date(this.endDate).getTime()) {
          this.$vux.toast.text('查询结束时间必须大于查询开始时间')
          return false
        }
        this.resultlist = [];
        this.accpentlist = [];
       this.getData()
      },
      getData() {
        if (this.startDate) {
          this.params.startDate = this.startDate + " 00:00:00";
        } else {
          this.params.startDate = null;
        }
        if (this.endDate) {
          this.params.endDate = this.endDate + " 00:00:00";
        } else {
          this.params.endDate = null;
        }
        if(this.checkType!=null&&this.checkType.length>0){
          this.params.checkType=this.checkType[0]
        } else {
          this.params.checkType = ""
        }
        this.params.isPlan = '0'
        this.$axiosAjax.getCheckList(this.params).then(res => {

          this.totalCount = res.data.result.totalCount;
          // this.accpentlist = res.data.result.items;

          let relist = res.data.result.items;
          if (this.params.skipCount == 0) {
              this.accpentlist = [];
          }
          this.accpentlist = this.accpentlist.concat(relist);
          let totalAllCount = res.data.result.totalCount;
          let resultCount = this.accpentlist.length;
          if (parseInt(resultCount) < parseInt(totalAllCount)) {
            this.$refs['scrollqq'].forceUpdate(true);
          } else {
            this.$refs['scrollqq'].forceUpdate(false);
          }
        });
      },
      goBack() {
        this.$bridge.callHandler({
              type: 'closePage',
              data: {}
            });
      },
      clearStartDate() {
        this.startDate = "";
      },
      clearEndDate() {
        this.endDate = "";
      },
      onPullingUp() {
        let limitcount = this.accpentlist.length;
        this.params.skipCount = limitcount;
        // if (this.params.skipCount + this.params.maxResultCount < this.totalCount) {
        //   this.params.skipCount = this.params.skipCount + this.params.maxResultCount;
        this.getData();
        // }
      },
      onPullingDown() {
        this.search();
      },
      getCheckTypeList(){
        this.$axiosAjax.getCheckTypeList({codeName: '安全检查类型'}).then(res => {
         if(res.data.success==true){
           var arr=[];
           res.data.result.forEach(item =>{
               arr.push(item.codeName)
             })
           this.checkTypeList.push(arr)
         }
        });
      },
      nodeClick(item) {
          if(this.num==0){
            this.params.beDepartName = item.departName
            this.params.checkDepartId = item.id
          }else{
            this.params.projectName = item.departName
            this.params.projectId = item.id
          }
        this.classValue = false
      },
      getCompany(num) {
        this.num=num;
        this.examinedUnits()
      },
      examinedUnits() {
        //debugger;//单位
        this.$axiosAjax.examinedUnits({parentId: -1}).then((res) => {
          if (res.data.success == true) {
            this.classValue = true;
            this.data = res.data.result;
            console.log(this.data);
          }
        }).catch(
          (err) => {

          }
        )
      },
    }
  };
</script>
<style lang="less" scoped>
  .search-btn {
    width: 200px;
    line-height: 36px;
    border-radius: 20px;
    margin: 23px auto;
    color: #fff;
    background: #469b7a;
    text-align: center;
    font-size:16px;
    letter-spacing: 4px;
  }

  .statues {
    font-size: 12px;
    font-weight: bold;

  }

  .classifyOneName {
    font-size: 12px;
    color: #666;
  }

  .lf {
    float: left;
    height: 100%;
    width: 70%;
    line-height: 25px;
  }

  .rf {
    float: right;
    height: 100%;
    width: 30%;
    line-height: 50px;
  }

  .form-item {
    .input_div {
      .vux-x-icon {
        fill: #999;
        float: right;
        margin-top: 18px;
      }

    }
  }

  .project_div {
    .project_list {
      box-sizing: border-box;
      padding-left: 20px;
      li {
        border-bottom: 1px solid #efeff4;
        height: 77px;
        position: relative;
        padding-top: 10px;
        padding-right: 22px;
        h4 {
          width: calc(100% - 50px);
          text-overflow: ellipsis;
          white-space: nowrap;
          overflow: hidden;
          font-size: 16px;
          margin-bottom: 8px;
          font-weight: bold;
        }

        p {
          span {
            font-size: 14px;
            color: #666;
          }

          span:first-child {
            margin-right: 40px;
          }

        }

        .project_status {
          margin-top: 14px;
          strong {
            font-size: 12px;
          }

          strong.project_status1 {
            color: #ff7333;
          }

          strong.project_status2 {
            color: #469b7a;
          }

        }

        .vux-x-icon {
          fill: #999;
          right: 20px;
          top: 50%;
          margin-top: -11px;
          position: absolute;
        }

      }
    }
  }

  .add_btn {
    position: fixed;
    height: 62px;
    width: 62px;
    right: 30px;
    bottom: 35px;
  }
</style>
<style>
  .hiddenlc .vux-cell-box .weui-cell {
    padding-right: 0 !important;
    border: 0 !important;
  }
  .hiddenlc .vux-cell-box:not(:first-child):before {
    border: none !important;
  }
</style>
